
*********************************************
****   Description   ************************
*********************************************

*This program runs a differences-in-differences analysis comparing advertising content between the Freedman's Savings Bank and other banks before and after the 1870 charter amendment of the Freedman's Savings Bank, generating "Figure 7. Persuasion Intensity Difference-in-Differences".


*********************************************
****   Data   *******************************
*********************************************
use "$Data/Advertising_BagofWords_December2024.dta", clear 
keep if Year>=1867 


*********************************************
****   Create Variables ************* 
*********************************************

gen treatante5 = (Year ==  1865 & FSB ==1)
gen treatante4 = (Year ==  1866 & FSB ==1)
gen treatante3 = (Year ==  1867 & FSB ==1)
gen treatante2 = (Year ==  1868 & FSB ==1)
gen treatante1 = (Year ==  1869 & FSB ==1)
 
gen treatyear = (Year ==  1870 & FSB ==1)
gen treatpost1 = (Year ==  1871 & FSB ==1)
gen treatpost2 = (Year ==  1872 & FSB ==1)
gen treatpost3 = (Year ==  1873 & FSB ==1)
gen treatpost4 = (Year ==  1874 & FSB ==1)


gen Coef=.
gen Lowci=.
gen Highci=.
global treatment  treatante3 treatante2  treatyear treatpost1 treatpost2 treatpost3 treatante1


*********************************************
****   Regression and Graph ************* 
*********************************************


foreach var of varlist  Prescriptions_tfidf  FalseClaims_tfidf  Sentiment_tfidf  {
	
	
display in red "`var'"
eststo: reghdfe `var'  $treatment, absorb(mo_date Bank) cluster(mo_date Bank) 

mat list r(table)  
mat A = r(table)    
mat se = A[2, 1..colsof(A)]
mat list se
replace Coef=_b[treatante3] if Year==1867
replace Coef=_b[treatante2] if Year==1868
replace Coef=0 if Year==1869
replace Coef=_b[treatyear] if Year==1870
replace Coef=_b[treatpost1] if Year==1871
replace Coef=_b[treatpost2] if Year==1872
replace Coef=_b[treatpost3] if Year==1873

replace Lowci=_b[treatante3]-_se[treatante3]*1.96 if Year==1867
replace Lowci=_b[treatante2]-_se[treatante2]*1.96 if Year==1868
replace Lowci=0 if Year==1869
replace Lowci=_b[treatyear]-_se[treatyear]*1.96 if Year==1870
replace Lowci=_b[treatpost1]-_se[treatpost1]*1.96 if Year==1871
replace Lowci=_b[treatpost2]-_se[treatpost2]*1.96 if Year==1872
replace Lowci=_b[treatpost3]-_se[treatpost3]*1.96 if Year==1873
tab Lowci

replace Highci=_b[treatante3]+_se[treatante3]*1.96 if Year==1867
replace Highci=_b[treatante2]+_se[treatante2]*1.96 if Year==1868
replace Highci=0 if Year==1869
replace Highci=_b[treatyear]+_se[treatyear]*1.96 if Year==1870
replace Highci=_b[treatpost1]+_se[treatpost1]*1.96 if Year==1871
replace Highci=_b[treatpost2]+_se[treatpost2]*1.96 if Year==1872
replace Highci=_b[treatpost3]+_se[treatpost3]*1.96 if Year==1873


preserve
collapse (mean) Coef Lowci Highci, by(Year)

sort Year
tsset Year, yearly

gr twoway (rcap Lowci Highci Year) (tsline Coef  if tin(1867,1873), ytitle("",height(5)) xtitle("",height(5)) graphregion( color(white) ) plotregion(  fcolor(white) ) xscale(range(1867 1868 1869 1870 1871 1872 1873) ) xlabel(1867 1868 1869 1870 1871 1872 1873 )  color(black) clwidth(thick) lpattern(solid) yline(0) legend(region(lwidth(none))) xline(1869) legend(off))
 
restore

} 

